<!DOCTYPE html>

<html xmlns:th="http://www.w3.org/1999/xhtml">
<!--
    @Describe 代码生成器生成
    @Author   Professor_Kong
    @Date     2019-05-21
    @Email    logwto@163.com
-->
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/scroll-bar.css">
    <link rel="stylesheet" href="/static/css/sub-page.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>常用页面</cite></a>
            <a><cite>代码生成器</cite></a>
            <a><cite>生成表单</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form" lay-filter="operateFormFilter" id="operateId">



        <div class="layui-form-item layui-inline" >

            <button class="layui-btn" id="obtBtn">获取连接</button>

            <div class="layui-input-inline">
                <select name="tableName" id="tableName">

                </select>
            </div>
        </div>

        <div class="layui-form-item layui-inline" >
            <label class="layui-form-label" style="width: 50px;padding: 9px 2px">用户名</label>
            <div class="layui-input-block" style="margin-left: 65px">
                 <input style="height: 32px" type="text" id="username" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" style="text-align: right">
            <div class="layui-input-block" style="margin-right: 40px">
                <button class="layui-btn" style="height: 32px; line-height: 32px" lay-submit lay-filter="operateFilter" id="operateSubBtn">提交</button>
                <button type="reset" style="height: 32px; line-height: 32px" class="layui-btn">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script th:inline="none">

    //js 获取
    var formBackFillData = window.parent.document.getElementById("hidArea").value;


    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        // laydate.render({
        //     elem: '#birthday',
        //     type: "datetime"
        // });

        form.verify({
            birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
        });

        form.on('submit(operateFilter)', function (data) {
            var arr = new Array();
            $.each(data.field,function (key,val) {
                // if(key.indexOf("like[")!=-1){
                //     arr.push(val)
                // }
                console.log(val)
            })
            var formData = data.field;
            formData['ids'] = arr;

            $.ajax({
                url:'/sys/user/addOrUpdate',
                type:'post',
                dataType:'json',
                data:formData,
                success: function (res) {
                    if(res.code== 1){
                        layer.alert("操作异常，请联系管理员！")
                    }else{
                        //重载table  触发父页面查询
                        parent.layui.$("#subBtn").click();
                        layer.msg("操作成功！", {icon: 6, time: 1000, anim: 4}, function () {
                            //关闭 表单弹窗
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    }
                }
            })

            return false;
        });
        
        $("#obtBtn").click(function () {
            var obj = JSON.parse(formBackFillData);
            console.log(obj);
            layer.alert(obj +"");
            return false;
        })
        

        function init() {
            //清空表单
            $("#operateId")[0].reset();
            console.log(typeof(formBackFillData) != "undefined" && formBackFillData!= '')
            if(typeof(formBackFillData) != "undefined" && formBackFillData!=''){
                form.val("operateFormFilter", JSON.parse(formBackFillData));
            }
            // $.ajax({
            //     url:'/sys/role/getRoleById',
            //     type:"post",
            //     data:{"id":data.id},
            //     dataType:'json',
            //     success:function (res) {
            //         if(res.length!=0){
            //             str = '';
            //             $.each(res,function (key, val) {
            //                 // name="like['+val.name+']"
            //                 if(val.status=='1'){
            //                     str += ' <input type="checkbox" value="'+val.id+'" name="like['+val.name+']" title='+val.name+' checked>'
            //                 }else{
            //                     str += ' <input type="checkbox" value="'+val.id+'" name="like['+val.name+']" title='+val.name+'> '
            //                 }
            //             });
            //             $("#checkBox").append(str);
            //         }
            //     }
            // });

            //清空 父页面传递的对象信息
            formBackFillData ='';
        };

        function getTableName(){
            $.ajax({
                url:'/sys/codeGenerator/getTableNames',
                dataType:'json',
                type:'post',
                data:JSON.parse(formBackFillData),
                success:function (res) {
                    if(res.code == 0){
                        $("#tableName").empty();

                        if(res.data.length>0){
                            $("#tableName").append('<option value="">请选择表</option>')
                            $.each(res.data,function (key, val) {
                                $("#tableName").append('<option value="'+val+'">'+val+'</option>');
                            })
                        }
                        form.render('select')
                    }else{
                        layer.alert(res.msg)
                    }

                }

            })
        }
        getTableName();
        // init();
    })
</script>
</body>
</html>
